using System;

namespace Beeflys
{
    sealed class Timer
    {
        public readonly static Timer Current = new Timer(new TimerOptions());
        public readonly static TimeSpan DefaultTimeSpan = default;

        internal Timer(TimerOptions options)
        {
            this.hashedWheelTimer = new HashedWheelTimer(
                    options.tickDuration, 
                    options.ticksPerWheel,
                    options.maxPendingTimeouts);
        }

        private HashedWheelTimer hashedWheelTimer;

        public ITimeout CreateTimeout(ITimerTask timerTask, TimeSpan timeSpan)
        {
            var timeout = this.hashedWheelTimer.NewTimeout(timerTask, timeSpan);

            return timeout;
        }

        public void Stop()
        {
            this.hashedWheelTimer.Stop();
        }
    }
}
